package com.yc.hwc.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hwc.bean.Task;
import com.yc.hwc.dao.SqlDao;

@RestController
@RequestMapping("task")
public class TaskDo extends BaseAction<Task>{
	
	@Resource
	private SqlDao dao;
	
	@RequestMapping("queryClsSnItems")
	List<?> queryClsSnItems(){
		return dao.find("select distinct cls_sn from user");
	}
	
	@RequestMapping("sumTask")
	Object sumTask(Long id){
		String sql = "SELECT\n" +
				"	a.*,z.name uname, z.in_time utime, z.head,y.name cname, b.user_all,\n" +
				"	ifnull(c.user_fnh,0) user_fnh\n" +
				"FROM\n" +
				"	task a" +
				"	join user z on a.in_user=z.id\n" +
				"	join course y on a.course_id=y.id\n" +
				"LEFT JOIN (\n" +
				"	SELECT\n" +
				"		count(*) user_all,\n" +
				"		cls_sn\n" +
				"	FROM\n" +
				"		user where role=1\n" +
				"	GROUP BY\n" +
				"		cls_sn\n" +
				") b ON a.cls_sn = b.cls_sn\n" +
				"LEFT JOIN (\n" +
				"	SELECT\n" +
				"		count(*) user_fnh,\n" +
				"		task_id\n" +
				"	FROM\n" +
				"		task_log a join user b on a.in_user=b.id and b.role=1\n" +
				"	GROUP BY\n" +
				"		task_id\n" +
				") c ON a.id = c.task_id\n" +
				"WHERE\n" +
				"	a.id = ?0";
		return dao.get(sql, id);
	}

}
